// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {HouseViewingApplyList} from '../domains/houseviewingapplylist.domain';
import {HouseViewingApply} from '../domains/houseviewingapply.domain';
import {ApplyTimeList} from '../domains/applytimelist.domain';

/**
 * 
 */
@Injectable({
  providedIn: 'root'
})
export class HouseViewingApplyServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'houseViewingApplyServiceSvr.assx/';
  }

  
  getApplyTime(token: string, houseId: string): Promise<ApplyTimeList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString());
    return this.request.post<ApplyTimeList>(this.baseUrl + 'getApplyTime', httpParams).then((res) => {
      return new ApplyTimeList(res);
    });
  }

  
  hasReviewEligibility(token: string, customerId: string, houseId: string): Promise<boolean> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('houseId', houseId.toString());
    return this.request.post<boolean>(this.baseUrl + 'hasReviewEligibility', httpParams).then((res) => {
      return res;
    });
  }

  
  getApplyTimeByRedis(houseId: string): Promise<ApplyTimeList> {
    const httpParams = new HttpParams()
      .append('houseId', houseId.toString());
    return this.request.post<ApplyTimeList>(this.baseUrl + 'getApplyTimeByRedis', httpParams).then((res) => {
      return new ApplyTimeList(res);
    });
  }

  
  updateHouseViewingApplyStatus(token: string, status: number, id: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('status', status.toString())
      .append('id', id.toString());
    return this.request.post<number>(this.baseUrl + 'updateHouseViewingApplyStatus', httpParams).then((res) => {
      return res;
    });
  }

  
  deleteHouseViewingApplyByPrimaryKeyByRedis(id: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('id', id.toString());
    return this.request.post<number>(this.baseUrl + 'deleteHouseViewingApplyByPrimaryKeyByRedis', httpParams).then((res) => {
      return res;
    });
  }

  
  listHouseViewingApply(token: string, status: number, skip: number, size: number): Promise<HouseViewingApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('status', status.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<HouseViewingApplyList>(this.baseUrl + 'listHouseViewingApply', httpParams).then((res) => {
      return new HouseViewingApplyList(res);
    });
  }

  
  deleteHouseViewingApplyByPrimaryKey(token: string, id: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString());
    return this.request.post<number>(this.baseUrl + 'deleteHouseViewingApplyByPrimaryKey', httpParams).then((res) => {
      return res;
    });
  }

  
  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  
  getApplyStatus(token: string, houseId: string, customerId: string): Promise<HouseViewingApply> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('houseId', houseId.toString())
      .append('customerId', customerId.toString());
    return this.request.post<HouseViewingApply>(this.baseUrl + 'getApplyStatus', httpParams).then((res) => {
      return new HouseViewingApply(res);
    });
  }

  
  saveHouseViewingApply(token: string, customerId: string, customerName: string, houseId: string, date: string, timeIndex: string): Promise<HouseViewingApply> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('customerName', customerName.toString())
      .append('houseId', houseId.toString())
      .append('date', date.toString())
      .append('timeIndex', timeIndex.toString());
    return this.request.post<HouseViewingApply>(this.baseUrl + 'saveHouseViewingApply', httpParams).then((res) => {
      return new HouseViewingApply(res);
    });
  }

  
  listHouseViewingApplyByCustomerId(token: string, customerId: string): Promise<HouseViewingApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString());
    return this.request.post<HouseViewingApplyList>(this.baseUrl + 'listHouseViewingApplyByCustomerId', httpParams).then((res) => {
      return new HouseViewingApplyList(res);
    });
  }
}
